<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false"%>
<html>
<head>
    <title>Listado de facturas</title>
    <style type="text/css" media="all">
          @import url("<spring:url value="/resources/css/efacturas.css"/>");
    </style>
</head>

<body>

	<script type="javascript">
	
		function generatePDF(){
			window.location = '/billing/invoice/report';
		}
	
	</script>

   <jsp:include page="header.jsp" />
   
   <jsp:include page="navigation.jsp" />

    <div id="content">
   
  <form:form action="/billing/addBill" commandName="invoice">
    
    <form:errors path="*" cssClass="error" element="div"/>      
      
    <fieldset>
    <legend>Datos de la factura</legend>
    
      <table>
          <tr>
              <td><form:label  path="payee">Beneficiario: ${invoice.payee.firstFamilyName}  ${invoice.payee.secondFamilyName},  ${invoice.payee.firstName}</form:label></td>

              <td><form:label  path="payer">Pagador: ${invoice.payer.firstFamilyName}  ${invoice.payer.secondFamilyName},  ${invoice.payer.firstName}</form:label></td>              
              
              <td><form:label  path="creationDate">Fecha: ${invoice.creationDate} </form:label></td>
          </tr>

        <tr>
            <td colspan="3">
                  <form:label path="description" >Descripcion</form:label>
                  <form:textarea rows="5" cols="150" path="description" />            
            </td>    
        </tr>
          
          <table>
         <tr>
                 <th align="center">Fecha</th>
                 <th align="center">Categoria</th>
                 <th align="center">Descripcion</th> 
                 <th align="center">Pagador</th>
                 <th align="center">Beneficiario</th>
                 <th align="center">Cantidad</th>
           </tr>
             
          <c:forEach var="bill" items="${invoice.billingEntries}">
            <tr>
              <td align="center">${bill.date    }</td>
              <td align="center">${bill.concept.description}</td>
              <td align="center">${bill.description}</td>
              <td align="center">${bill.payer.firstFamilyName} ${bill.payer.secondFamilyName}, ${bill.payer.firstName}</td>
              <td align="center">${bill.payee.firstFamilyName} ${bill.payee.secondFamilyName}, ${bill.payee.firstName}</td>
              <td align="right">${bill.amount}</td>
                
            </tr>
          </c:forEach>
          
          <tr><td colspan="6" align="rigth"> Total a pagar: ${invoice.totalAmount} </td>    </tr>
          </table>
      </table>
    </fieldset>
    
    <input type="submit" value="Guardar" /> | <input type="button" onClick="generatePDF()" value="Generar PDF" /> 
  </form:form>

    </div>
    
    <div id="footer">
        Copyright © Victor Ferrer, 2012
    </div>

</body>
</html>

